﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GFrame.Data;
using GFrame.Shadow;
using GFrame.Shadow.Search;
using EZCRS.HCMS.Entity;

namespace EZCRS.HCMS.Bll.AIR
{
    public class TAChannel
    {
        private ShadowSearch<Channel> _search;

        public TAChannel()
        {
            _search = new ShadowSearch<Channel>();

            _search.ConnectionName = MainBase.CONNECTION_STRING;
        }

        public List<Channel> GetAll()
        {
            return _search.Search(string.Empty);
        }

        public Channel GetItem(int ID)
        {

            List<Channel> lst = _search.Search("ID = " + ID.ToString());

            if (lst.Count > 0)
                return lst[0];

            return null;

        }


        public bool Delete(int ID)
        {
            Channel cl = GetItem(ID);

            Shadow<Channel> sha = new Shadow<Channel>(cl);

            sha.ConnectionName = MainBase.CONNECTION_STRING;

            return sha.Delete();

        }

        public bool Save(Channel obj)
        {
            Shadow<Channel> sha = new Shadow<Channel>(obj);

            sha.ConnectionName = MainBase.CONNECTION_STRING;

            return sha.Save();
        }

        public List<Channel> GetItems(int PageIndex, int PageSize, out int RecordCount, out int PageCount)
        {
            ShadowRule rule = new ShadowRule();

            rule.PageSize = PageSize;
            rule.PageIndex = PageIndex;

            List<Channel> lst = _search.Search("", rule);

            RecordCount = rule.RecordCount;
            PageCount = rule.PageCount;

            return lst;

        }
    }
}
